package com.coincalf.wallet.blockchain.bean.trx;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * TRX地址信息 ...
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TrxAddress implements Serializable {
    private static final long serialVersionUID = 6946829338235509384L;

    @JsonProperty("address")
    private String address; //hex格式地址

    @JsonProperty("balance")
    private BigDecimal balance = BigDecimal.ZERO; //余额 单位 sun

    @JsonProperty("create_time")
    private Long createTime;

    @JsonProperty("latest_opration_time")
    private Long latestOprationTime;

    //免费的带宽可使用 可使用带宽 = 5000 - freeNetUsage
    @JsonProperty("free_net_usage")
    private BigDecimal freeNetUsage;

    @JsonProperty("latest_consume_free_time")
    private Long latestConsumeFreeTime;

    @JsonProperty("account_resource")
    private AccountResource accountResource;


    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class AccountResource {

        @JsonProperty("energy_usage")
        private BigDecimal energyUsage;

        //为获取能量而冻结的余额
        @JsonProperty("frozen_balance_for_energy")
        private BigDecimal frozenBalanceForEnergy;

        @JsonProperty("latest_consume_time_for_energy")
        private BigDecimal latestConsumeTimeForEnergy;

    }


    /**
     *{
     *     "address": "41983e00a976bb9759e5fed5a063d6c91a1fd5bf64",
     *     "balance": 13245970, //可用余额
     *     "frozen": [  //为获取带宽而冻结的TRX数量 如果没有 则 frozen 字段为空
     *         {
     *             "frozen_balance": 5000000,       //冻结的TRX数量 单位:Sun
     *             "expire_time": 1599460785000     //到期时间,可赎回时间
     *         }
     *     ],
     *     "create_time": 1597893318000,
     *     "latest_opration_time": 1599201669000,
     *     "free_net_usage": 1038,  //已使用的带宽  可用带宽 = 5000 - 已使用的带宽
     *     "latest_consume_free_time": 1599201669000,
     *     "account_resource": {
     *         "energy_usage": 28,  //已使用的能量  可用能量 = 总能量 - 已使用的能量
     *         "frozen_balance_for_energy": {   //为获取能量而冻结的TRX数量 如果没有 则 frozen_balance_for_energy 字段为空
     *             "frozen_balance": 8000000,   //冻结的TRX数量 单位:Sun
     *             "expire_time": 1599460869000 //到期时间,可赎回时间
     *         },
     *         "latest_consume_time_for_energy": 1599123777000
     *     },
     *     "owner_permission": {
     *         "permission_name": "owner",
     *         "threshold": 1,
     *         "keys": [
     *             {
     *                 "address": "41983e00a976bb9759e5fed5a063d6c91a1fd5bf64",
     *                 "weight": 1
     *             }
     *         ]
     *     },
     *     "active_permission": [
     *         {
     *             "type": "Active",
     *             "id": 2,
     *             "permission_name": "active",
     *             "threshold": 1,
     *             "operations": "7fff1fc0033e0300000000000000000000000000000000000000000000000000",
     *             "keys": [
     *                 {
     *                     "address": "41983e00a976bb9759e5fed5a063d6c91a1fd5bf64",
     *                     "weight": 1
     *                 }
     *             ]
     *         }
     *     ]
     * }
     * 获得带宽 = 为获取带宽冻结的TRX / 整个网络当中为获取带宽而冻结的TRX总数
     * 获得能量 = 为获取能量冻结的TRX / 整个网络当中为获取能量而冻结的TRX总数*总能量限制
     *
     * 注意：如果地址未激活，则返回 {}
     */

}
